﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SSG_cs
{
    public partial class frmSSG : Form
    {
        public frmSSG()
        {
            InitializeComponent();
        }

        public class dat
        {
            public int x;
            public int y;

            public dat(int _x, int _y)
            {
                x = _x;
                y = _y;
            }

            public dat()
            {
                x = 0;
                y = 0;
            }

        }

        private DataSet _ds;
        private void frmSSG_Load(object sender, EventArgs e)
        {
            _ds = new DataSet();
            _ds.Tables.Add();
            _ds.Tables[0].Columns.Add("x", typeof(int));
            _ds.Tables[0].Columns.Add("y", typeof(int));

            for (int x = 0; x < 32; x++)
            {
                _ds.Tables[0].Rows.Add(new object[] { x, x * 2 });
            }

            chart1.Series.Clear();
            chart1.DataSource = _ds.Tables[0];
            chart1.Series.Add("ssg");
            chart1.Series[0].XValueMember  = "x";
            chart1.Series[0].YValueMembers = "y";
            chart1.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
            chart1.DataBind();

            
            int num = 32;
            int width = gbScrolls.Width/num;
            for (int i = 0; i < num; i++)
            {
                VScrollBar vs = new VScrollBar();
                vs.Top = 0;
                vs.Width  = width;
                vs.Height = gbScrolls.Height;
                vs.Left   = width*i;
                vs.Minimum = -100;
                vs.Maximum = 100;
                vs.Tag    = i;
                
                vs.Value = (int)_ds.Tables[0].Rows[i]["y"];
                vs.Scroll += new ScrollEventHandler(vs_Scroll);
                gbScrolls.Controls.Add(vs);              
            }

            chart1.ChartAreas[0].Axes[1].Minimum = -100;
            chart1.ChartAreas[0].Axes[1].Maximum = 100;
            chart1.ChartAreas[0].Axes[1].MaximumAutoSize = 100;

        }

        void vs_Scroll(object sender, ScrollEventArgs e)
        {
            VScrollBar vs = (VScrollBar)sender;

            _ds.Tables[0].Rows[(int)vs.Tag]["y"] = vs.Value;
            chart1.DataBind();
        }

        private void gbScrolls_Resize(object sender, EventArgs e)
        {
            int num = 32;
            int width = gbScrolls.Width/num;

            foreach (VScrollBar vs in gbScrolls.Controls)
            {
                vs.Top = 0;
                vs.Width  = width;
                vs.Height = gbScrolls.Height;
                vs.Left   = width*(int)vs.Tag;
            }

        }
    }
}
